package com.entmanage.base.controller;

import com.entmanage.common.utils.StringUtils;
import io.swagger.annotations.Api;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.entmanage.common.annotation.Log;
import com.entmanage.common.core.controller.BaseController;
import com.entmanage.common.core.domain.AjaxResult;
import com.entmanage.common.enums.BusinessType;
import com.entmanage.base.domain.BiShow;
import com.entmanage.base.service.IBiShowService;
import com.entmanage.common.utils.poi.ExcelUtil;

/**
 * 产品展示信息Controller
 *
 * @author hjh
 * @date 2025-07-23
 */
@Api(tags = {"bi-ZxShowMenu模块"}, description = "产品展示信息")
@RestController
@RequestMapping("/bi/bi_show")
public class BiShowController extends BaseController
{
    @Autowired
    private IBiShowService zxShowMenuService;

    /**
     * 查询产品展示信息列表
     */
    @PreAuthorize("@ss.hasPermi('bi:bi_show:list')")
    @GetMapping("/list")
    public AjaxResult list(BiShow zxShowMenu) {

        List<BiShow> list = zxShowMenuService.selectZxShowMenuList(zxShowMenu);
        return success(list);
    }

    /**
     * 导出产品展示信息列表
     */
    @PreAuthorize("@ss.hasPermi('bi:bi_show:export')")
    @Log(title = "产品展示信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BiShow zxShowMenu)
    {
        List<BiShow> list = zxShowMenuService.selectZxShowMenuList(zxShowMenu);
        ExcelUtil<BiShow> util = new ExcelUtil<BiShow>(BiShow.class);
        util.exportExcel(response, list, "产品展示信息数据");
    }

    /**
     * 获取产品展示信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('bi:bi_show:query')")
    @GetMapping(value = "/{menuId}")
    public AjaxResult getInfo(@PathVariable("menuId") Long menuId)
    {
        return success(zxShowMenuService.selectZxShowMenuByMenuId(menuId));
    }

    /**
     * 新增产品展示信息
     */
    @PreAuthorize("@ss.hasPermi('bi:bi_show:add')")
    @Log(title = "产品展示信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BiShow zxShowMenu)
    {
        return toAjax(zxShowMenuService.insertZxShowMenu(zxShowMenu));
    }

    /**
     * 修改产品展示信息
     */
    @PreAuthorize("@ss.hasPermi('bi:bi_show:edit')")
    @Log(title = "产品展示信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BiShow zxShowMenu)
    {
        return toAjax(zxShowMenuService.updateZxShowMenu(zxShowMenu));
    }

    /**
     * 删除产品展示信息
     */
    @PreAuthorize("@ss.hasPermi('bi:bi_show:remove')")
    @Log(title = "产品展示信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{menuIds}")
    public AjaxResult remove(@PathVariable Long[] menuIds)
    {
        return toAjax(zxShowMenuService.deleteZxShowMenuByMenuIds(menuIds));
    }
    @GetMapping("/show")
    public String getShowDate(ModelMap mmap)
    {
        return "show";
    }
    @PostMapping("/showList")
    public Map<String,Object> getShowDate(@RequestBody BiShow zxShowMenu)
    {
        Map<String,Object> mmp =  new HashMap<>();
        // 获取父级信息
        BiShow parentShow = new BiShow();
        List<BiShow> showData = new ArrayList<>();
        // 查显示的数据
        zxShowMenu.setVisible("Y");
        //如果MenuId不为空，表示跳下级
        if(!StringUtils.isNull(zxShowMenu.getMenuId()) ){
            parentShow = zxShowMenuService.selectZxShowMenuByMenuId(zxShowMenu.getMenuId());
            zxShowMenu.setParentId(parentShow.getMenuId());
            showData = zxShowMenuService.selectZxShowMenuList(zxShowMenu);
        }else if(!StringUtils.isNull(zxShowMenu.getParentId()) && zxShowMenu.getParentId() != 0) { //getParentId不为空表示跳4
            showData = zxShowMenuService.selectZxShowMenuList(zxShowMenu);
            parentShow = zxShowMenuService.selectZxShowMenuByMenuId(zxShowMenu.getParentId());
        }else {
            parentShow.setMenuType("");
            parentShow.setParentId(Long.valueOf(0));
            showData = zxShowMenuService.selectZxShowMenuList(zxShowMenu);
        }

        mmp.put("showData", showData);
        mmp.put("parentMenuType", parentShow.getMenuType());
        mmp.put("parentShow", parentShow);
        return mmp;
    }
}
